/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-04-25     zxj       the first version
 */

#include <rtthread.h>
#include <rtdevice.h>

#include <string.h>
#include <stdlib.h>

#include "app_dbg_mp.h"
#include "app_dbg_util.h"
#include "app_dbg_drv.h"

#include "app_ntc_drv.h"
#include "app_sys_param.h"


#ifdef RT_USING_FINSH

static int dbg(int argc, char **argv)
{
    UINT8 cmd = DBG_CMD_CONN;
    int result = RT_EOK;

    if (argc > 1) 
    {
        if (!strcmp(argv[1], "pcba"))
        {
            if(app_dbg_drv_connect(DBG_CONN_PCBA)){
               // rt_kprintf("connect ok\n");
                app_dbg_rx_msg_post(cmd, NULL, 0);
            }else{
                rt_kprintf("connect err\n");
            }
        }  

        if (!strcmp(argv[1], "prod"))
        {
            if(app_dbg_drv_connect(DBG_CONN_PROD)){
               // rt_kprintf("connect ok\n");
                app_dbg_rx_msg_post(cmd, NULL, 0);
            }else{
                rt_kprintf("connect err\n");
            }
        }         

        if (!strcmp(argv[1], "test"))
        {
            UINT8 strtem[50]={0};
            UINT8 pdata[6]={0};

           // rt_memcpy(strtem, pdata, 6);
           // rt_kprintf("pdata= %s\n",pdata);
            app_sys_param_set(APP_SYS_PARAM_PROC_SN, SYS_PARAM_TYPE_STR, "");
            rt_memset(strtem, 0 , sizeof(strtem));
            app_sys_param_get(APP_SYS_PARAM_PROC_SN, strtem, sizeof(strtem));
            rt_kprintf("strtem= %s\n",pdata);
        }   

        
    } 
    else 
    {
        rt_kprintf("dbg: \n");
        rt_kprintf("dbg <pcpa/prod> - please input \"pcba\" \n");
        result = -RT_ERROR;
    }
    return RT_EOK;
}
MSH_CMD_EXPORT(dbg, dbg function);

#endif /* RT_USING_FINSH */
